// create by dplord at 2017-02-06 16:37

#include <iostream>
#include <string>
#include <vector>
#include <fstream>
#include <sstream>
#include <map>
#include <unordered_map>

#include "unistd.h"
#include "pthread.h"

using namespace std;

struct thread_param_struct {
    int age;
    string name;
};

void* thread_main(void* arg) {
    int i = 0;
    thread_param_struct* param_struct = ((thread_param_struct *)arg);

    printf("name = %s, age = %d", (param_struct->name).c_str(), param_struct->age);
    return NULL;
}


/**
 * 线程函数传进去一个结构体参数
 *
 * @param argc
 * @param argv
 * @return
 */
int main(int argc, char **argv) {
    pthread_t tid;
    thread_param_struct* thread_param = new thread_param_struct;
    thread_param->age = 12;
    thread_param->name = "nihao";

    if(pthread_create(&tid, NULL, thread_main, (void *) thread_param) != 0) {
        printf("thread create error");
    }

    //给线程函数留下足够的运行时间
    sleep(10);
    return 0;
}